class PalindromeList {
public:
    ListNode* middlenode(ListNode* head)
    {
        ListNode* slow, * fast;
        slow = fast = head;
        if (fast && fast->next)
        {
            slow->next;
            fast->next->next;
        }
        return slow;
    }
    ListNode* reversenode(ListNode* head)
    {
        ListNode* n1, * n2, * n3;
        n1 = NULL;
        n2 = head;
        if (n2)
            n3 = n2->next;
        while (n2)
        {
            n2->next = n1;
            n1 = n2;
            n2 = n3;
            if (n3)
                n3 = n3->next;
        }
        return n1;
    }
    bool chkPalindrome(ListNode* A)
    {
        ListNode* mid = middlenode(A);
        ListNode* rid = reversenode(mid);
        while (A && rid)
        {
            if (A->val != rid->val)
            {
                return false;
            }
            A = A->next;
            rid = rid->next;
        }
        return true;
    }
};